package com.snail.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.snail.model.dto.BizUserTaskRecordDto;
import com.snail.model.pojo.BizUserTaskRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
* @author Monica
* @description 针对表【biz_user_task_record(用户任务记录表)】的数据库操作Mapper
* @createDate 2025-07-23 14:30:24
* @Entity com.snail.model.pojo.BizUserTaskRecord
*/
public interface BizUserTaskRecordMapper extends BaseMapper<BizUserTaskRecord> {


    /**
     * 联表查询用户任务记录和任务信息
     * @param userId 用户ID
     * @return 用户任务记录DTO列表
     */
    @Select("SELECT ur.*, t.task_name, t.task_description " +
            "FROM biz_user_task_record ur " +
            "LEFT JOIN biz_task t ON ur.task_id = t.id " +
            "WHERE ur.user_id = #{userId} AND ur.status = 1")
    List<BizUserTaskRecordDto> selectUserTaskRecordWithTaskInfo(@Param("userId") Long userId);




    @Select("SELECT COUNT(1) FROM biz_user_task_record " +
            "WHERE user_id = #{userId} AND task_id = #{taskId} AND DATE(complete_time) = CURDATE()")
    int countTodayVideoPoints(@Param("userId") Long userId,
                              @Param("taskId") Long taskId);

}




